import java.sql.*;

/**
 * @Auther: zephyrus
 * @Date: 2023/11/23
 * @Description:
 * @since
 */
public class TestInsert {
    public static void main(String[] args) throws SQLException {
        //利用jdbc-driver驱动操作数据库
        //1. 加载驱动程序
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("找不到驱动");
        }
        Connection conn=null;
        //2. 创建连接
        try {
            conn= DriverManager
                    .getConnection("jdbc:mysql://localhost:3306/jsp","root","root");
        } catch (SQLException e) {
            System.out.println("创建连接失败");
        }
        //3 创建语句对象
//        Statement st=conn.createStatement();
        PreparedStatement ps=conn.prepareStatement("insert into tb_user(username,password,real_name) values(?,?,?)");
        ps.setString(1,"wangwu");
        ps.setString(2,"wangwu");
        ps.setString(3,"wangwu");
        //执行语句 insert update delete
        int count=ps.executeUpdate();
                //st.executeUpdate("insert into tb_user(username,password,real_name) values('lisi','lisi','李四')");


        if(count==1){
            System.out.println("数据更新成功");
        }else{
            System.out.println("数据更新失败");
        }

        ps.close();
        conn.close();
    }
}
